int daysBetween(DateTime a, DateTime b, [bool ignoreTime = false]) {
  if (ignoreTime) {
    int v = a.millisecondsSinceEpoch ~/ 86400000 - b.millisecondsSinceEpoch ~/ 86400000;
    if (v < 0) return -v;
    return v;
  } else {
    int v = a.millisecondsSinceEpoch - b.millisecondsSinceEpoch;
    if (v < 0) v = -v;
    return v ~/ 86400000;
  }
}

// current timestamp
int currentTimeMillis() {
  return new DateTime.now().millisecondsSinceEpoch;
}

String currentDate() {
  return DateTime.fromMillisecondsSinceEpoch(currentTimeMillis()).toString();
}

// 十位时间戳转日期，dart中时间戳是十三位
String timestamp2date(int timestamp) {
  return DateTime.fromMillisecondsSinceEpoch(timestamp * 1000).toString().substring(0, 10);
}

String timestamp10toDateWithoutSecond(int timestamp) {
  return DateTime.fromMillisecondsSinceEpoch(timestamp * 1000).toString().substring(0, 16);
}

String timestamp13toDateWithoutSecond(int timestamp) {
  return DateTime.fromMillisecondsSinceEpoch(timestamp).toString().substring(0, 16);
}

String getMinuteHourDayMonthReadableTime(int timestamp) {
  if (timestamp == null || timestamp == 0) {
    return "";
  }
  String dateWithoutSecond = timestamp10toDateWithoutSecond(timestamp);
  int currentTimeStamp = currentTimeMillis();

  String currentDateWithoutSecond = timestamp13toDateWithoutSecond(currentTimeStamp);
  if (timestamp > currentTimeStamp) {
    // 未来时间
    return dateWithoutSecond;
  }
  int betweenDays = daysBetween(
      DateTime.parse(currentDateWithoutSecond.substring(0, 10)), DateTime.parse(dateWithoutSecond.substring(0, 10)));
  if (betweenDays == 0) {
    // 小时相等
    if (dateWithoutSecond.substring(11, 13) == currentDateWithoutSecond.substring(11, 13)) {
      // 判断分钟
      if (dateWithoutSecond.substring(14) == currentDateWithoutSecond.substring(14)) {
        // 分钟相等
        return "1分钟前";
      } else {
        int big = int.parse(currentDateWithoutSecond.substring(14));
        int small = int.parse(dateWithoutSecond.substring(14));
        if (big - small <= 0) {
          return "1分钟前";
        } else {
          return "${big - small}分钟前";
        }
      }
    }
  } else if (betweenDays == 1) {
  } else if (betweenDays == 2) {
  } else if (betweenDays < 30) {
  } else if (betweenDays < 12 * 30) {
  } else {
    return dateWithoutSecond;
  }
}

main() {
  int betweenDays = daysBetween(DateTime.parse('2020-08-08'), DateTime.parse("2020-08-08"), false);
  print("betweenDays == $betweenDays");
}

String recordUpdateTimeFormat(int timestamp) {
  if (timestamp == null || timestamp == 0) {
    return "";
  }
  int currentTimestamp = currentTimeMillis();
  if (timestamp.toString().length == 10) {
    timestamp *= 1000;
  }
  int deltaTimestamp = currentTimestamp - timestamp;
  if (deltaTimestamp < 0) {
    return timestamp13toDateWithoutSecond(timestamp);
  } else {
    if (deltaTimestamp <= 1 * 60 * 1000 || deltaTimestamp == 0) {
      return "1分钟前";
    } else if (deltaTimestamp < 60 * 60 * 1000) {
      return "${deltaTimestamp / 1000 / 60}分钟前";
    } else if (deltaTimestamp < 24 * 60 * 60 * 1000) {
      return "${deltaTimestamp / 1000 / 60 / 60}小时前";
    } else {
      return "${deltaTimestamp / 1000 / 60 / 60 / 24}日前";
    }
  }
}
